package GUI;

import util.User;
import util.UserDAO;
import util.ThemeManager;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.border.MatteBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.RoundRectangle2D;

/**
 * 主界面窗口类
 */
public class MainFrame extends JFrame {
    private User currentUser;
    private JPanel contentPanel;
    private CardLayout cardLayout;

    // 添加缺少的标签变量
    private JLabel welcomeLabel;
    private JLabel userPointsLabel;

    // 侧边栏按钮
    private JButton travelRecordButton;
    private JButton carbonReductionButton;
    private JButton dataAnalysisButton;
    private JButton socialButton;
    private JButton profileButton;
    private JButton travelNavigationButton;
    private JButton newsButton;
    private JButton settingsButton;
    private JButton aboutUsButton;
    private JButton activeButton;

    // 各功能面板
    private TravelRecordPanel travelRecordPanel;
    private CarbonReductionPanel carbonReductionPanel;
    private DataAnalysisPanel dataAnalysisPanel;
    private SocialPanel socialPanel;
    private ProfilePanel profilePanel;
    private TravelNavigationPanel travelNavigationPanel;
    private NewsPanel newsPanel;

    // 面板标识常量
    private static final String TRAVEL_RECORD = "travelRecord";
    private static final String CARBON_REDUCTION = "carbonReduction";
    private static final String DATA_ANALYSIS = "dataAnalysis";
    private static final String SOCIAL = "social";
    private static final String PROFILE = "profile";
    private static final String TRAVEL_NAVIGATION = "travelNavigation";
    private static final String NEWS = "news";
    private static final String SETTINGS = "settings";
    private static final String ABOUT_US = "aboutUs";

    /**
     * 主界面构造函数
     *
     * @param user 当前登录用户
     */
    public MainFrame(User user) {
        this.currentUser = user;

        // 初始化窗口设置
        setTitle("绿色出行系统");
        setSize(1200, 800);
        setMinimumSize(new Dimension(900, 700));
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null); // 居中显示

        // 设置窗口图标（如果有）
        // setIconImage(new ImageIcon("path/to/icon.png").getImage());

        // 创建主面板
        JPanel mainPanel = new JPanel(new BorderLayout());
        mainPanel.setBackground(new Color(245, 248, 250));

        // 添加顶部面板
        mainPanel.add(createTopPanel(), BorderLayout.NORTH);

        // 添加侧边栏和内容面板
        JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
                createSidebarPanel(),
                createContentPanel());
        splitPane.setDividerSize(1);
        splitPane.setDividerLocation(220);
        splitPane.setEnabled(false); // 禁止用户调整分隔条
        splitPane.setBorder(null);
        mainPanel.add(splitPane, BorderLayout.CENTER);

        // 添加状态栏
        mainPanel.add(createStatusBar(), BorderLayout.SOUTH);

        // 设置主面板为窗口内容面板
        setContentPane(mainPanel);
    }

    /**
     * 创建顶部面板
     */
    private JPanel createTopPanel() {
        JPanel topPanel = new JPanel(new BorderLayout());
        topPanel.setBackground(new Color(0, 160, 0));
        topPanel.setPreferredSize(new Dimension(getWidth(), 60));
        topPanel.setBorder(new EmptyBorder(10, 15, 10, 15));

        // 创建应用标题
        JLabel titleLabel = new JLabel("绿色出行系统");
        titleLabel.setFont(new Font("等线", Font.BOLD, 20));
        titleLabel.setForeground(Color.WHITE);
        topPanel.add(titleLabel, BorderLayout.WEST);

        // 创建用户信息面板
        JPanel userInfoPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
        userInfoPanel.setOpaque(false);

        // 添加积分显示
        userPointsLabel = new JLabel("积分: " + currentUser.getPoints());
        userPointsLabel.setFont(new Font("等线", Font.PLAIN, 14));
        userPointsLabel.setForeground(Color.WHITE);
        userPointsLabel.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createLineBorder(new Color(255, 255, 255, 100), 1, true),
                BorderFactory.createEmptyBorder(5, 10, 5, 10)));
        userInfoPanel.add(userPointsLabel);

        // 添加用户名显示
        welcomeLabel = new JLabel("欢迎, " + currentUser.getUsername() + " ");
        welcomeLabel.setFont(new Font("等线", Font.PLAIN, 14));
        welcomeLabel.setForeground(Color.WHITE);
        userInfoPanel.add(welcomeLabel);

        // 添加退出按钮
        JButton logoutButton = new JButton("退出");
        logoutButton.setFont(new Font("等线", Font.PLAIN, 14));
        logoutButton.setForeground(new Color(0, 130, 0));
        logoutButton.setBackground(Color.WHITE);
        logoutButton.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10));
        logoutButton.setFocusPainted(false);
        logoutButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
        logoutButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                logout();
            }
        });
        userInfoPanel.add(logoutButton);

        topPanel.add(userInfoPanel, BorderLayout.EAST);

        return topPanel;
    }

    /**
     * 创建侧边栏面板
     */
    private JPanel createSidebarPanel() {
        JPanel sidebarPanel = new JPanel(new BorderLayout());
        sidebarPanel.setBackground(new Color(240, 245, 240));
        sidebarPanel.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 1, new Color(220, 220, 220)));

        // 创建用户信息面板
        JPanel userPanel = new JPanel(new BorderLayout());
        userPanel.setBackground(new Color(230, 240, 230));
        userPanel.setBorder(new EmptyBorder(15, 15, 15, 15));

        // 显示用户头像
        JLabel avatarLabel = new CircleAvatar(currentUser.getUsername(), 70);
        avatarLabel.setAlignmentX(Component.CENTER_ALIGNMENT);

        // 头像面板（居中）
        JPanel avatarPanel = new JPanel();
        avatarPanel.setOpaque(false);
        avatarPanel.add(avatarLabel);
        userPanel.add(avatarPanel, BorderLayout.CENTER);

        // 添加用户基本信息
        JPanel infoPanel = new JPanel();
        infoPanel.setLayout(new BoxLayout(infoPanel, BoxLayout.Y_AXIS));
        infoPanel.setOpaque(false);
        infoPanel.setBorder(new EmptyBorder(8, 0, 0, 0));

        JLabel nameLabel = new JLabel(currentUser.getUsername());
        nameLabel.setFont(new Font("等线", Font.BOLD, 16));
        nameLabel.setForeground(new Color(50, 50, 50));
        nameLabel.setAlignmentX(Component.CENTER_ALIGNMENT);

        JLabel levelLabel = new JLabel("等级: " + getUserLevel(currentUser.getPoints()));
        levelLabel.setFont(new Font("等线", Font.PLAIN, 14));
        levelLabel.setForeground(new Color(100, 100, 100));
        levelLabel.setAlignmentX(Component.CENTER_ALIGNMENT);

        infoPanel.add(nameLabel);
        infoPanel.add(Box.createVerticalStrut(5));
        infoPanel.add(levelLabel);

        // 用户信息居中
        JPanel centerInfoPanel = new JPanel();
        centerInfoPanel.setOpaque(false);
        centerInfoPanel.add(infoPanel);
        userPanel.add(centerInfoPanel, BorderLayout.SOUTH);

        sidebarPanel.add(userPanel, BorderLayout.NORTH);

        // 创建导航按钮面板
        JPanel navPanel = new JPanel();
        navPanel.setLayout(new BoxLayout(navPanel, BoxLayout.Y_AXIS));
        navPanel.setBackground(new Color(240, 245, 240));
        navPanel.setBorder(new EmptyBorder(15, 0, 0, 0));

        // 创建导航按钮
        travelNavigationButton = createNavButton("出行导航", null);
        travelRecordButton = createNavButton("出行记录", null);
        carbonReductionButton = createNavButton("碳减排", null);
        dataAnalysisButton = createNavButton("数据分析", null);
        newsButton = createNavButton("资讯中心", null);
        socialButton = createNavButton("社交分享", null);
        profileButton = createNavButton("个人资料", null);
        settingsButton = createNavButton("设置", null);
        aboutUsButton = createNavButton("关于我们", null);

        // 添加导航按钮到面板
        navPanel.add(createCategoryLabel("主要功能"));
        navPanel.add(travelNavigationButton);
        navPanel.add(travelRecordButton);
        navPanel.add(carbonReductionButton);
        navPanel.add(dataAnalysisButton);

        navPanel.add(Box.createVerticalStrut(15));
        navPanel.add(createCategoryLabel("社区"));
        navPanel.add(newsButton);
        navPanel.add(socialButton);

        navPanel.add(Box.createVerticalStrut(15));
        navPanel.add(createCategoryLabel("个人"));
        navPanel.add(profileButton);
        navPanel.add(settingsButton);
        navPanel.add(aboutUsButton);

        // 添加填充空间
        navPanel.add(Box.createVerticalGlue());

        // 添加版本信息
        JLabel versionLabel = new JLabel("绿色出行 v1.0.0");
        versionLabel.setFont(new Font("等线", Font.PLAIN, 12));
        versionLabel.setForeground(new Color(120, 120, 120));
        versionLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
        versionLabel.setBorder(new EmptyBorder(10, 0, 15, 0));

        JPanel versionPanel = new JPanel();
        versionPanel.setOpaque(false);
        versionPanel.add(versionLabel);
        navPanel.add(versionPanel);

        sidebarPanel.add(new JScrollPane(navPanel,
                JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER);

        // 默认选中出行记录按钮
        setActiveButton(travelRecordButton);

        return sidebarPanel;
    }

    /**
     * 创建分类标签
     */
    private JLabel createCategoryLabel(String text) {
        JLabel label = new JLabel(text);
        label.setFont(new Font("等线", Font.BOLD, 12));
        label.setForeground(new Color(150, 150, 150));
        label.setBorder(BorderFactory.createEmptyBorder(5, 25, 5, 15));
        label.setAlignmentX(Component.LEFT_ALIGNMENT);
        return label;
    }

    /**
     * 创建导航按钮
     */
    private JButton createNavButton(String text, String iconPath) {
        JButton button = new JButton(text);
        button.setFont(new Font("等线", Font.PLAIN, 15));
        button.setForeground(new Color(80, 80, 80));
        button.setBackground(new Color(240, 245, 240));
        button.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createEmptyBorder(0, 0, 0, 0),
                BorderFactory.createEmptyBorder(10, 15, 10, 15)));
        button.setHorizontalAlignment(SwingConstants.LEFT);
        button.setFocusPainted(false);
        button.setCursor(new Cursor(Cursor.HAND_CURSOR));
        button.setMaximumSize(new Dimension(220, 40));

        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                handleNavigation(button);
            }
        });

        return button;
    }

    /**
     * 处理导航按钮点击
     */
    private void handleNavigation(JButton clicked) {
        // 更新按钮状态
        setActiveButton(clicked);

        // 根据点击的按钮显示相应面板
        if (clicked == travelRecordButton) {
            cardLayout.show(contentPanel, TRAVEL_RECORD);
        } else if (clicked == carbonReductionButton) {
            cardLayout.show(contentPanel, CARBON_REDUCTION);
        } else if (clicked == dataAnalysisButton) {
            cardLayout.show(contentPanel, DATA_ANALYSIS);
        } else if (clicked == socialButton) {
            cardLayout.show(contentPanel, SOCIAL);
        } else if (clicked == profileButton) {
            cardLayout.show(contentPanel, PROFILE);
        } else if (clicked == travelNavigationButton) {
            cardLayout.show(contentPanel, TRAVEL_NAVIGATION);
        } else if (clicked == newsButton) {
            cardLayout.show(contentPanel, NEWS);
        } else if (clicked == settingsButton) {
            // 显示设置面板，首次点击时创建
            boolean settingsPanelExists = false;
            for (Component component : contentPanel.getComponents()) {
                if (component.getName() != null && component.getName().equals(SETTINGS)) {
                    settingsPanelExists = true;
                    break;
                }
            }

            if (!settingsPanelExists) {
                JPanel settingsPanel = createSettingsPanel();
                settingsPanel.setName(SETTINGS); // 重要：设置组件名称
                contentPanel.add(settingsPanel, SETTINGS);
            }
            cardLayout.show(contentPanel, SETTINGS);
        } else if (clicked == aboutUsButton) {
            // 显示关于我们面板，首次点击时创建
            boolean aboutUsPanelExists = false;
            for (Component component : contentPanel.getComponents()) {
                if (component.getName() != null && component.getName().equals(ABOUT_US)) {
                    aboutUsPanelExists = true;
                    break;
                }
            }

            if (!aboutUsPanelExists) {
                JPanel aboutUsPanel = createAboutUsPanel();
                aboutUsPanel.setName(ABOUT_US); // 重要：设置组件名称
                contentPanel.add(aboutUsPanel, ABOUT_US);
            }
            cardLayout.show(contentPanel, ABOUT_US);
        }
    }

    /**
     * 设置当前活跃按钮
     */
    private void setActiveButton(JButton button) {
        // 如果有当前活跃按钮，恢复其默认样式
        if (activeButton != null) {
            activeButton.setBackground(new Color(240, 245, 240));
            activeButton.setForeground(new Color(80, 80, 80));
            activeButton.setBorder(BorderFactory.createCompoundBorder(
                    BorderFactory.createEmptyBorder(0, 0, 0, 0),
                    BorderFactory.createEmptyBorder(10, 15, 10, 15)));
        }

        // 设置新的活跃按钮样式
        button.setBackground(new Color(220, 240, 220));
        button.setForeground(new Color(0, 130, 0));
        button.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createMatteBorder(0, 4, 0, 0, new Color(0, 160, 0)),
                BorderFactory.createEmptyBorder(10, 11, 10, 15)));

        activeButton = button;
    }

    /**
     * 创建内容面板
     */
    private JPanel createContentPanel() {
        cardLayout = new CardLayout();
        contentPanel = new JPanel(cardLayout);
        contentPanel.setBackground(Color.WHITE);

        // 创建各功能面板
        travelRecordPanel = new TravelRecordPanel(currentUser);
        carbonReductionPanel = new CarbonReductionPanel(currentUser);
        dataAnalysisPanel = new DataAnalysisPanel(currentUser);
        socialPanel = new SocialPanel(currentUser);
        profilePanel = new ProfilePanel(currentUser);
        travelNavigationPanel = new TravelNavigationPanel(currentUser);
        newsPanel = new NewsPanel(currentUser);

        // 添加面板到卡片布局
        contentPanel.add(travelRecordPanel, TRAVEL_RECORD);
        contentPanel.add(carbonReductionPanel, CARBON_REDUCTION);
        contentPanel.add(dataAnalysisPanel, DATA_ANALYSIS);
        contentPanel.add(socialPanel, SOCIAL);
        contentPanel.add(profilePanel, PROFILE);
        contentPanel.add(travelNavigationPanel, TRAVEL_NAVIGATION);
        contentPanel.add(newsPanel, NEWS);

        return contentPanel;
    }

    /**
     * 创建底部状态栏
     */
    private JPanel createStatusBar() {
        JPanel statusBar = new JPanel(new BorderLayout());
        statusBar.setBackground(new Color(240, 240, 240));
        statusBar.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, new Color(220, 220, 220)));
        statusBar.setPreferredSize(new Dimension(getWidth(), 25));

        JLabel statusLabel = new JLabel(" 系统状态: 正常运行中");
        statusLabel.setFont(new Font("等线", Font.PLAIN, 12));
        statusLabel.setForeground(new Color(100, 100, 100));
        statusBar.add(statusLabel, BorderLayout.WEST);

        JLabel versionLabel = new JLabel("版本 1.0.0 ");
        versionLabel.setFont(new Font("等线", Font.PLAIN, 12));
        versionLabel.setForeground(new Color(100, 100, 100));
        statusBar.add(versionLabel, BorderLayout.EAST);

        return statusBar;
    }

    /**
     * 退出登录
     */
    private void logout() {
        int option = JOptionPane.showConfirmDialog(
                this,
                "确定要退出登录吗？",
                "退出登录",
                JOptionPane.YES_NO_OPTION);

        if (option == JOptionPane.YES_OPTION) {
            LoginFrame loginFrame = new LoginFrame();
            loginFrame.setVisible(true);
            dispose();
        }
    }

    /**
     * 更新用户信息
     */
    public void updateUserInfo(User user) {
        this.currentUser = user;

        // 更新界面上的用户信息
        welcomeLabel.setText("欢迎, " + currentUser.getName());
        userPointsLabel.setText("积分: " + currentUser.getPoints());

        // 更新个人信息面板
        if (profilePanel != null) {
            profilePanel.refreshData();
        }
    }

    /**
     * 更新用户积分
     */
    public void updateUserPoints(int points) {
        currentUser.setPoints(points);

        // 更新保存到数据库
        UserDAO userDAO = new UserDAO();
        userDAO.updateUser(currentUser);

        // 更新界面上的积分显示
        userPointsLabel.setText("积分: " + currentUser.getPoints());

        // 如果个人信息面板已创建，刷新它的数据
        if (profilePanel != null) {
            profilePanel.refreshData();
        }
    }

    /**
     * 根据积分计算用户等级
     */
    private String getUserLevel(int points) {
        if (points < 100) {
            return "初级绿行者";
        } else if (points < 500) {
            return "中级绿行者";
        } else if (points < 1000) {
            return "高级绿行者";
        } else if (points < 2000) {
            return "绿行达人";
        } else {
            return "绿行大师";
        }
    }

    /**
     * 圆形头像标签类
     */
    private class CircleAvatar extends JLabel {
        private String text;
        private int size;
        private Color bgColor;

        public CircleAvatar(String text, int size) {
            this.text = text.substring(0, 1).toUpperCase(); // 取第一个字符作为头像
            this.size = size;
            this.bgColor = new Color(0, 160, 0);
            setPreferredSize(new Dimension(size, size));
        }

        @Override
        protected void paintComponent(Graphics g) {
            Graphics2D g2 = (Graphics2D) g.create();
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

            // 绘制圆形背景
            g2.setColor(bgColor);
            g2.fillOval(0, 0, size, size);

            // 绘制边框
            g2.setColor(new Color(255, 255, 255, 100));
            g2.setStroke(new BasicStroke(2));
            g2.drawOval(1, 1, size - 2, size - 2);

            // 绘制文本
            g2.setColor(Color.WHITE);
            g2.setFont(new Font("Arial", Font.BOLD, size / 2));
            FontMetrics fm = g2.getFontMetrics();
            int textWidth = fm.stringWidth(text);
            int textHeight = fm.getHeight();
            g2.drawString(text, (size - textWidth) / 2, (size + textHeight / 2) / 2);

            g2.dispose();
        }
    }

    /**
     * 创建设置面板
     */
    private JPanel createSettingsPanel() {
        JPanel panel = new JPanel(new BorderLayout(20, 20));
        panel.setBackground(ThemeManager.getColor(ThemeManager.PANEL_BACKGROUND_COLOR));
        panel.setBorder(new EmptyBorder(30, 40, 30, 40));

        // 标题
        JLabel titleLabel = new JLabel("设置");
        titleLabel.setFont(new Font("等线", Font.BOLD, 28));
        titleLabel.setForeground(ThemeManager.getColor(ThemeManager.TEXT_COLOR));
        panel.add(titleLabel, BorderLayout.NORTH);

        // 内容面板
        JPanel contentPanel = new JPanel();
        contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
        contentPanel.setBackground(ThemeManager.getColor(ThemeManager.PANEL_BACKGROUND_COLOR));

        // 通知设置
        JPanel notificationPanel = createSettingCategory("通知设置", "管理应用通知偏好");
        JCheckBox pushCheckBox = new JCheckBox("推送通知", true);
        JCheckBox emailCheckBox = new JCheckBox("邮件通知", false);
        JCheckBox smsCheckBox = new JCheckBox("短信通知", false);

        // 设置样式
        styleCheckBox(pushCheckBox);
        styleCheckBox(emailCheckBox);
        styleCheckBox(smsCheckBox);

        notificationPanel.add(pushCheckBox);
        notificationPanel.add(Box.createVerticalStrut(10));
        notificationPanel.add(emailCheckBox);
        notificationPanel.add(Box.createVerticalStrut(10));
        notificationPanel.add(smsCheckBox);

        // 隐私设置
        JPanel privacyPanel = createSettingCategory("隐私设置", "管理谁可以看到您的信息");
        JCheckBox publicProfileCheckBox = new JCheckBox("公开个人资料", true);
        JCheckBox showPointsCheckBox = new JCheckBox("显示我的积分", true);
        JCheckBox shareLocationCheckBox = new JCheckBox("分享我的位置", false);

        // 设置样式
        styleCheckBox(publicProfileCheckBox);
        styleCheckBox(showPointsCheckBox);
        styleCheckBox(shareLocationCheckBox);

        privacyPanel.add(publicProfileCheckBox);
        privacyPanel.add(Box.createVerticalStrut(10));
        privacyPanel.add(showPointsCheckBox);
        privacyPanel.add(Box.createVerticalStrut(10));
        privacyPanel.add(shareLocationCheckBox);

        // 添加所有设置类别到内容面板
        contentPanel.add(notificationPanel);
        contentPanel.add(Box.createVerticalStrut(25));
        contentPanel.add(privacyPanel);

        // 按钮面板
        JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
        buttonPanel.setOpaque(false);
        buttonPanel.setBorder(BorderFactory.createEmptyBorder(20, 0, 0, 0));

        JButton saveButton = new JButton("保存设置");
        saveButton.setFont(new Font("等线", Font.BOLD, 14));
        saveButton.setBackground(ThemeManager.getColor(ThemeManager.PRIMARY_COLOR));
        saveButton.setForeground(ThemeManager.getColor(ThemeManager.BUTTON_TEXT_COLOR));
        saveButton.setFocusPainted(false);
        saveButton.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createLineBorder(new Color(0, 100, 0), 1),
                BorderFactory.createEmptyBorder(8, 20, 8, 20)));
        saveButton.setCursor(new Cursor(Cursor.HAND_CURSOR));

        saveButton.addActionListener(e -> {
            // 保存设置逻辑
            JOptionPane.showMessageDialog(this, "设置已保存", "成功", JOptionPane.INFORMATION_MESSAGE);
        });

        JButton resetButton = new JButton("重置默认");
        resetButton.setFont(new Font("等线", Font.PLAIN, 14));
        resetButton.setBackground(new Color(240, 240, 240));
        resetButton.setForeground(new Color(80, 80, 80));
        resetButton.setFocusPainted(false);
        resetButton.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createLineBorder(new Color(200, 200, 200), 1),
                BorderFactory.createEmptyBorder(8, 15, 8, 15)));
        resetButton.setCursor(new Cursor(Cursor.HAND_CURSOR));

        resetButton.addActionListener(e -> {
            // 重置设置逻辑
            pushCheckBox.setSelected(true);
            emailCheckBox.setSelected(false);
            smsCheckBox.setSelected(false);
            publicProfileCheckBox.setSelected(true);
            showPointsCheckBox.setSelected(true);
            shareLocationCheckBox.setSelected(false);
        });

        buttonPanel.add(resetButton);
        buttonPanel.add(Box.createHorizontalStrut(10));
        buttonPanel.add(saveButton);

        // 添加滚动面板
        JScrollPane scrollPane = new JScrollPane(contentPanel);
        scrollPane.setBorder(null);
        scrollPane.getVerticalScrollBar().setUnitIncrement(16);
        scrollPane.getViewport().setBackground(ThemeManager.getColor(ThemeManager.PANEL_BACKGROUND_COLOR));
        panel.add(scrollPane, BorderLayout.CENTER);

        panel.add(buttonPanel, BorderLayout.SOUTH);

        return panel;
    }

    /**
     * 设置复选框样式
     */
    private void styleCheckBox(JCheckBox checkBox) {
        checkBox.setOpaque(false);
        checkBox.setFont(new Font("等线", Font.PLAIN, 14));
        checkBox.setForeground(ThemeManager.getColor(ThemeManager.TEXT_COLOR));
        checkBox.setAlignmentX(Component.LEFT_ALIGNMENT);
    }

    /**
     * 更新主题颜色
     */
    private void updateThemeColors() {
        // 更新主窗口背景
        setBackground(ThemeManager.getColor(ThemeManager.BACKGROUND_COLOR));

        // 更新侧边栏颜色
        if (activeButton != null) {
            setActiveButton(activeButton);
        }
    }

    /**
     * 创建设置类别面板
     */
    private JPanel createSettingCategory(String title, String description) {
        JPanel panel = new JPanel();
        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
        panel.setBackground(ThemeManager.getColor(ThemeManager.PANEL_BACKGROUND_COLOR));
        panel.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createMatteBorder(0, 0, 1, 0, ThemeManager.getColor(ThemeManager.BORDER_COLOR)),
                BorderFactory.createEmptyBorder(10, 0, 20, 0)));
        panel.setAlignmentX(Component.LEFT_ALIGNMENT);

        // 标题
        JLabel titleLabel = new JLabel(title);
        titleLabel.setFont(new Font("等线", Font.BOLD, 18));
        titleLabel.setForeground(ThemeManager.getColor(ThemeManager.PRIMARY_COLOR));
        titleLabel.setAlignmentX(Component.LEFT_ALIGNMENT);

        // 描述
        JLabel descLabel = new JLabel(description);
        descLabel.setFont(new Font("等线", Font.PLAIN, 14));
        descLabel.setForeground(ThemeManager.getColor(ThemeManager.SECONDARY_TEXT_COLOR));
        descLabel.setAlignmentX(Component.LEFT_ALIGNMENT);

        panel.add(titleLabel);
        panel.add(Box.createVerticalStrut(5));
        panel.add(descLabel);
        panel.add(Box.createVerticalStrut(20));

        return panel;
    }

    /**
     * 创建关于我们面板
     */
    private JPanel createAboutUsPanel() {
        JPanel panel = new JPanel(new BorderLayout(20, 20));
        panel.setBackground(ThemeManager.getColor(ThemeManager.PANEL_BACKGROUND_COLOR));
        panel.setBorder(new EmptyBorder(20, 20, 20, 20));

        // 内容面板
        JPanel contentPanel = new JPanel();
        contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
        contentPanel.setBackground(ThemeManager.getColor(ThemeManager.PANEL_BACKGROUND_COLOR));

        // 应用信息面板 - 改为更现代的设计
        JPanel appInfoPanel = new JPanel(new BorderLayout(30, 0));
        appInfoPanel.setBackground(ThemeManager.getColor(ThemeManager.PANEL_BACKGROUND_COLOR));
        appInfoPanel.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createLineBorder(new Color(230, 240, 230), 1, true),
                BorderFactory.createEmptyBorder(30, 35, 30, 35)));

        // 应用信息左侧（文本）
        JPanel appTextPanel = new JPanel();
        appTextPanel.setLayout(new BoxLayout(appTextPanel, BoxLayout.Y_AXIS));
        appTextPanel.setOpaque(false);

        JLabel appNameLabel = new JLabel("绿色出行系统");
        appNameLabel.setFont(new Font("等线", Font.BOLD, 24));
        appNameLabel.setForeground(ThemeManager.getColor(ThemeManager.PRIMARY_COLOR));
        appNameLabel.setAlignmentX(Component.LEFT_ALIGNMENT);

        JLabel versionLabel = new JLabel("版本 1.0.0");
        versionLabel.setFont(new Font("等线", Font.PLAIN, 15));
        versionLabel.setForeground(ThemeManager.getColor(ThemeManager.SECONDARY_TEXT_COLOR));
        versionLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
        versionLabel.setBorder(BorderFactory.createEmptyBorder(5, 0, 20, 0));

        JTextArea descriptionArea = new JTextArea(
                "绿色出行系统是一个旨在鼓励人们采用环保交通方式的应用程序。" +
                        "通过记录用户的出行方式，计算碳排放量，提供数据分析，" +
                        "我们希望帮助用户更好地了解自己的出行习惯，并为环保事业贡献一份力量。");
        descriptionArea.setFont(new Font("等线", Font.PLAIN, 15));
        descriptionArea.setWrapStyleWord(true);
        descriptionArea.setLineWrap(true);
        descriptionArea.setEditable(false);
        descriptionArea.setBackground(ThemeManager.getColor(ThemeManager.PANEL_BACKGROUND_COLOR));
        descriptionArea.setForeground(ThemeManager.getColor(ThemeManager.TEXT_COLOR));
        descriptionArea.setAlignmentX(Component.LEFT_ALIGNMENT);

        appTextPanel.add(appNameLabel);
        appTextPanel.add(versionLabel);
        appTextPanel.add(descriptionArea);

        // 应用信息右侧（logo） - 使用更大的logo
        JPanel logoPanel = new JPanel(new BorderLayout());
        logoPanel.setOpaque(false);
        logoPanel.setPreferredSize(new Dimension(150, 150));

        JLabel logoLabel = new JLabel("🌿", JLabel.CENTER);
        logoLabel.setFont(new Font("Dialog", Font.PLAIN, 100));
        logoLabel.setForeground(ThemeManager.getColor(ThemeManager.SUCCESS_COLOR));
        logoPanel.add(logoLabel, BorderLayout.CENTER);

        appInfoPanel.add(appTextPanel, BorderLayout.CENTER);
        appInfoPanel.add(logoPanel, BorderLayout.EAST);

        contentPanel.add(appInfoPanel);
        contentPanel.add(Box.createVerticalStrut(25));

        // 学校信息和联系方式合并成一个面板
        JPanel infoPanel = new JPanel(new BorderLayout(0, 20));
        infoPanel.setBackground(ThemeManager.getColor(ThemeManager.PANEL_BACKGROUND_COLOR));
        infoPanel.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createLineBorder(new Color(230, 240, 230), 1, true),
                BorderFactory.createEmptyBorder(25, 35, 25, 35)));

        // 上半部分 - 学校信息
        JPanel universityPanel = new JPanel();
        universityPanel.setLayout(new BoxLayout(universityPanel, BoxLayout.Y_AXIS));
        universityPanel.setOpaque(false);
        universityPanel.setAlignmentX(Component.CENTER_ALIGNMENT);

        JLabel universityLabel = new JLabel("桂林电子科技大学XXX开发");
        universityLabel.setFont(new Font("等线", Font.BOLD, 18));
        universityLabel.setForeground(new Color(50, 120, 50));
        universityLabel.setAlignmentX(Component.CENTER_ALIGNMENT);

        universityPanel.add(universityLabel);
        universityPanel.add(Box.createVerticalStrut(5));

        // 下半部分 - 联系方式
        JPanel contactPanel = new JPanel();
        contactPanel.setLayout(new BoxLayout(contactPanel, BoxLayout.Y_AXIS));
        contactPanel.setOpaque(false);
        contactPanel.setAlignmentX(Component.CENTER_ALIGNMENT);

        JLabel contactTitleLabel = new JLabel("联系我们");
        contactTitleLabel.setFont(new Font("等线", Font.BOLD, 16));
        contactTitleLabel.setForeground(ThemeManager.getColor(ThemeManager.TEXT_COLOR));
        contactTitleLabel.setAlignmentX(Component.CENTER_ALIGNMENT);

        JLabel emailLabel = new JLabel("Email: support@greentravel.com");
        emailLabel.setFont(new Font("等线", Font.PLAIN, 15));
        emailLabel.setForeground(ThemeManager.getColor(ThemeManager.TEXT_COLOR));
        emailLabel.setAlignmentX(Component.CENTER_ALIGNMENT);

        contactPanel.add(contactTitleLabel);
        contactPanel.add(Box.createVerticalStrut(10));
        contactPanel.add(emailLabel);

        // 将学校信息和联系方式添加到信息面板
        infoPanel.add(universityPanel, BorderLayout.NORTH);
        infoPanel.add(contactPanel, BorderLayout.CENTER);

        contentPanel.add(infoPanel);
        contentPanel.add(Box.createVerticalStrut(20));

        // 版权信息
        JPanel copyrightPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
        copyrightPanel.setOpaque(false);

        JLabel copyrightLabel = new JLabel("© 2025 绿色出行团队. 保留所有权利.");
        copyrightLabel.setFont(new Font("等线", Font.ITALIC, 12));
        copyrightLabel.setForeground(new Color(150, 150, 150));

        copyrightPanel.add(copyrightLabel);
        contentPanel.add(copyrightPanel);

        // 添加滚动面板
        JScrollPane scrollPane = new JScrollPane(contentPanel);
        scrollPane.setBorder(null);
        scrollPane.getVerticalScrollBar().setUnitIncrement(16);
        scrollPane.getViewport().setBackground(ThemeManager.getColor(ThemeManager.PANEL_BACKGROUND_COLOR));
        panel.add(scrollPane, BorderLayout.CENTER);

        return panel;
    }
}
